home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12896 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c,comp.os.ms-windows.programmer.win32
  4. Subject: Re: How can I check whether I file exists in a multi-user environment?
  5. Date: Wed, 03 Apr 96 12:40:22 GMT
  6. Organization: none
  7. Message-ID: <828535222snz@genesis.demon.co.uk>
  8. References: <4jh4tl$t4c_002@chem.uva.nl> <Dp1oM8.Cns@iquest.net> <4jjn1d$clu@solutions.solon.com> <Dp6sqL.Buz@iquest.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <Dp6sqL.Buz@iquest.net> dlmiller@iquest.net "Doug Miller" writes:
  15.  
  16. >seebs@solutions.solon.com (Peter Seebach) wrote:
  17.  
  18. >>>#include <io.h>
  19. >>>int file_exists (char *filename) {
  20. >>>      return (access(filename, 0) == 0);
  21. >>>} /* returns -1 if file exists, 0 if it does not */
  22. >>
  23. >>The reason this is a poor solution is that it doesn't test for existance,
  24. >>it tests for accessibility.
  25. >
  26. >You should check your facts more carefully.  You evidently are unfamiliar with
  27. > the behavior of
  28. >access( ).  It is defined thusly:
  29. >
  30. >#include <io.h>
  31. >int access (const char *filename, int amode);
  32. >
  33. >permissible values for amode are:
  34. >        06      check for read and write permission
  35. >        04      check for read permission
  36. >        02      check for write permission
  37. >        01      execute
  38. >>>>>    00      check for existence of file     <<<<<
  39.  
  40. This is simply a poor description. access() is a function that is portable
  41. across many platforms being derived from the Unix/POSIX definition (but isn't
  42. standard C). It can only check for the existence of a file where that file is
  43. accessible, it does not bypass filesystem permissions. Even under DOS/Windows
  44. this is an issue for network drives. access() if first and foremost a test
  45. for accessibility, only if that condition is met can it test for
  46. existence/readability/writability. Worse than that in its correct POSIX
  47. guise it may perform the test using different criteria than those
  48. applied to fopen(), open() etc. which is why in general you should avoid
  49. it and use something like stat() or fopen() directly.
  50.  
  51. -- 
  52. -----------------------------------------
  53. Lawrence Kirby | fred@genesis.demon.co.uk
  54. Wilts, England | 70734.126@compuserve.com
  55. -----------------------------------------
  56.